#include<iostream>
using namespace std;
#include<vector>
#include<unordered_map>
#include<queue>
class Solution {
public:
    class cmp {
    public:
        bool operator()(pair<int, int>& a1, pair<int, int>& a2) {
            return a1.second > a2.second;
        }
    };
    vector<int> topKFrequent(vector<int>& nums, int k) {
        unordered_map<int, int> ma;
        for (auto& e : nums)
            ++ma[e];
        priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> que;
        for (auto& e : ma)
            que.push(e);
        while (que.size() > k)
            que.pop();
        vector<int> ans;
        while (!que.empty()) {
            ans.push_back(que.top().first);
            que.pop();
        }
        return ans;
    }
};
int main() {
    vector<int> nums{ 1,1,1,2,2,3 };
    int k = 2;
    Solution().topKFrequent(nums, 2);
}